package cn.itcast.usermanage.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import cn.itcast.usermanage.bean.DateGridResult;
import cn.itcast.usermanage.mapper.UserMapper;
import cn.itcast.usermanage.pojo.User;
import cn.itcast.usermanage.service.UserService;

@Service
public class UserServiceImpl implements UserService {

	//注入dao层对象
	@Autowired
	private UserMapper userMapper;
	
	@Override
	public DateGridResult queryPageUserList(Integer pageNum, Integer pageSize) {
//		pageNum = (pageNum-1)*pageSize;
//		List<User> rows=userMapper.queryPageUserList(pageNum, pageSize);
//		Long total = userMapper.countTotal();
//		
		//使用分页助手开始分页
		PageHelper.startPage(pageNum, pageSize);
//		分页拦截器会自动对接下来的查询进行分页
		List<User>  list= userMapper.queryUserPageList();
		//封装分页信息对象
		PageInfo<User> pageInfo = new PageInfo<>(list);
		

		//将查询加过添加到DateGridResult对象中
		DateGridResult result = new DateGridResult();
		result.setRows(list);
		result.setTotal(pageInfo.getTotal());
		return result;
	}

	@Override
	public void save(User user) {
		userMapper.save(user);
		
	}

	@Override
	public void delete(String ids) {
		userMapper.delete(ids);
		
	}

	@Override
	public void delete1(Long[] ids) {
		userMapper.delete1(ids);
	}
}
